package com.zhihui.online.exception;


import com.zhihui.online.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class GlobalException  {

    // 全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<Object> error(Exception e)
    {
        return Result.fail().message("系统出错啦，请联系管理员！");
    }
    // 特定异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result<Object> error(ArithmeticException e)
    {
        return Result.fail().message("除0异常");
    }
    // 自定义异常
    @ExceptionHandler(MyCustomerException.class)
    @ResponseBody
    public Result<Object>  error(MyCustomerException e)
    {
        return Result.fail().code(e.getCode()).message(e.getMessage());
    }
//    /**
//     * spring security异常
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(AccessDeniedException.class)
//    @ResponseBody
//    public Result<Object> error(AccessDeniedException e) throws AccessDeniedException {
//        return Result.fail().code(ResultCodeEnum.PERMISSION.getCode()).message("没有当前操作权限");
//    }
}
